#include "stdafx.h"

#include "Config.h"
#include "IniFile.h"


CConfig::CConfig(void)
{
	memset(&m_UserInfo,0,sizeof(TUserInfo));
	memset(&m_ClientInfo,0,sizeof(TClientInfo));
}


CConfig::~CConfig(void)
{
	
}

#define  SEC_USERINFO "UserInfo"
#define  SEC_SRVINFO "SrvInfo"

#define  USERINFO_USER "UserName"
#define  USERINFO_PSW  "PassWord"

#define  SRVINFO_IP "ServerIP"
void CConfig::LoadConfig(char* fileName)
{
	CIniFile inifile;
	if(!inifile.OpenIniFile(fileName))
	{
		strcpy(m_ClientInfo.srvIP,A_SRVIP); //set defualt ip
	}
	else
	{
		//const char* ch;
		const char* ch = NULL;
		ch = inifile.ReadString(SEC_USERINFO,USERINFO_USER,"test");
		strcpy(m_UserInfo.userName,ch);

		ch = inifile.ReadString(SEC_USERINFO,USERINFO_PSW,"123456");
		strcpy(m_UserInfo.userPsw,ch);

		ch = inifile.ReadString(SEC_SRVINFO,SRVINFO_IP,A_SRVIP);
		strcpy(m_ClientInfo.srvIP,ch);
	}

	inifile.CloseIniFile();	
}

void CConfig::SaveConfig(char* fileName)
{
	CIniFile inifile;
	inifile.OpenIniFile(fileName);
	inifile.WriteString(SEC_USERINFO,USERINFO_USER,m_UserInfo.userName);
	inifile.WriteString(SEC_USERINFO,USERINFO_PSW,m_UserInfo.userPsw);

	inifile.WriteString(SEC_SRVINFO,SRVINFO_IP,m_ClientInfo.srvIP);

	inifile.WriteIniFile(fileName);
}

